<include file="../header" />
</head>
<body class="J_scroll_fixed">
<script type="text/javascript">
    function onlyNumber(obj){
        //得到第一个字符是否为负号
        var t = obj.value.charAt(0);
        //先把非数字的都替换掉，除了数字和.
        if(obj.value != 0)
        obj.value = obj.value.replace(/[^\d\.]/g,'').replace(/^0{1,}/g,'');
        //必须保证第一个为数字而不是.
        obj.value = obj.value.replace(/^\./g,'');
        //保证只有出现一个.而没有多个.
        obj.value = obj.value.replace(/\.{2,}/g,'.');
        //保证.只出现一次，而不能出现两次以上
        obj.value = obj.value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
        //只能输入两位小数
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
        //如果第一位是负号，则允许添加
        if(t == '-'){
            return;
        }


        var price = parseFloat("{$workorder.price}");
        var sale_price = parseFloat($("input[name=sale_price]").val());
        var discont = sale_price/price * 100;
        $("a[name=discont]").html(parseInt(discont)+"%");
    }

    $(function() {
        $("button.btn_submit").click(function() {

            if ($("input[name=outstore_date]").val() == "") {
                alert("选择【出库日期】");
                $("input[name=outstore_date]").focus();
                return false;
            }

            if($("input[name=completed]").is(':checked')) {
                var paymentPrice = $("input[name=payment_price]").val();
                var minimumPercent = $("input[name=minimum_percent]").val();
                var salePrice = $("input[name=sale_price]").val();
                if (paymentPrice < (salePrice / 100 * minimumPercent)) {
                    alert("【付款金额】不得低于 " + minimumPercent + "%");
                    $("input[name=payment_price]").focus();
                    return false;
                }

                if ($("select[name=client_info_id]").val() == 0) {
                    alert("请选择【客户】");
                    $("select[name=client_info_id]").focus();
                    return false;
                }

                if ($("select[name=outstore_store_id]").val() == 0) {
                    alert("请选择【发货仓】");
                    $("select[name=outstore_store_id]").focus();
                    return false;
                }

                if ($("select[name=payment_status]").val() == 0) {
                    alert("请选择【付款情况】");
                    $("select[name=payment_status]").focus();
                    return false;
                }

                if ($("input[name=payment_price]").val() == "") {
                    alert("请填写【付款金额】");
                    $("input[name=payment_price]").focus();
                    return false;
                }

                if ($("input[name=delivery_place]").val() == "") {
                    alert("请填写【交货地点】");
                    $("input[name=delivery_place]").focus();
                    return false;
                }

                if ($("input[name=outstore_name]").val() == "") {
                    alert("请填写【产品名称】");
                    $("input[name=outstore_name]").focus();
                    return false;
                }

                if ($("input[name=sale_price]").val() == "") {
                    alert("请填写【销售金额】");
                    $("input[name=sale_price]").focus();
                    return false;
                }

                if ($("select[name=outstore_auditor]").val() == 0) {
                    alert("请选择【复核人】");
                    $("select[name=outstore_auditor]").focus();
                    return false;
                }

                if (confirm("是否确认【销售" + $("input[name=btnText]").val() + "】？")) {
                    $("button.btn_submit").hide();
                } else {
                    return false;
                }
            }else{
                $("button.btn_submit").hide();
            }

        });

        $("input[name=completed]").click(function() {
            if($("input[name=completed]").is(':checked')) {
                $("button.btn_submit").text("出库审核");
                $("input[name=btnText]").val("出库审核")
            }else{
                $("button.btn_submit").text("更新");
                $("input[name=btnText]").val("更新")
            }
        });

        $("select[name='payment_status']").change(function () {
            if($("select[name='payment_status']").find("option:selected").text() == "未付款"){
                $("input[name=payment_price]").val("0");
            }
        });

        $("select[name='client_info_id']").change(function () {
            var id = $("select[name='client_info_id']").val();
            var listArr=<?php echo json_encode($listClientInfo);?>;
            var list=eval(listArr);
            for(var i=0;i<list.length;i++){
                if(list[i]["client_info_id"] == id){
                    $("input[name=minimum_percent]").val(list[i]["minimum_percent"]*100);
                    if($("select[name='client_info_id']").find("option:selected").text() == "个人客户"){
                        break
                    }
                    $("input[name=contact]").val(list[i]["contact"]);
                    $("input[name=mobile]").val(list[i]["mobile"]);
                    $("input[name=address]").val(list[i]["address"]);
                    break;
                }
            }

        });

    });

</script>
<style type="text/css">
    .img-process{
        width: 70px;
        height: 70px;
    }
</style>
<form class="well form-search"  style="float:left;width:100%;margin-bottom: -20px" >
    <php>$imgVersion = "2020051401";</php>
    <a style="color:#45a1de;font-weight: bold;font-size: large">定制产品销售出库单</a>
    &nbsp;&nbsp;&nbsp;
    <if condition="$workorder['outstore_status'] gt '-1'">
        <a style="color: #1cc385;font-weight: bold;font-size: large">（已审核）</a>
        <else/>
        <a style="color: #ed7667;font-weight: bold;font-size: large">（未审核）</a>
    </if>
    <br/><br/>
    <div class="search_type cc mb10">
        <div >
            <span class="mr20">
                工单号：<input type="text" value="{$workorder.workorder_no}" readonly/>&nbsp;
                患者：<input type="text" value="{$patient.patient_name}，{$patient.sex}，{$patient.age}岁 {$workorder.side}" readonly/>&nbsp;
                业务员：<input type="text" style="width: 110px" value="{$sales.admin_name}" readonly/>&nbsp;
                处方人：<input type="text" style="width: 110px" value="{$prescriber.admin_name}" readonly/>
            </span>
        </div>
        <br/>
        <php>
            $processStatusArr=explode(",",$workorder["process_status"]);
            if(in_array($workorder["workorder_type"],array('1','5','6','7')))
            $processArr = array("取阴模", "检查取阴模","修阳模","检查修阳模","热塑成型","检查热塑成型","打磨抛光","检查打磨抛光","组装对线","半成品适配","穿戴及使用训练","入库");
            if(in_array($workorder["workorder_type"],array('2','4')))
            $processArr = array("取阴模2", "检查取阴模2","修阳模2","检查修阳模2","热塑成型","检查热塑成型","打磨抛光","检查打磨抛光","组装对线","半成品适配2","穿戴及使用训练2","入库");
            for($i = 0; $i < 12; $i++){
            if($processStatusArr[$i] == "1"){
            $processArr[$i] .= "亮";
            }
            }
        </php>
        <td>
            工序：
            <if condition="$orthosisProcess[0] eq '1'">
                <img class="img-process" id="process1" src="/Template/images/{$processArr.0}.png?v={$imgVersion}" title="取阴模"/>
            </if>
            <if condition="$orthosisProcess[1] eq '1'">
                <img class="img-process" id="process2" src="/Template/images/{$processArr.1}.png?v={$imgVersion}" title="检查取阴模"/>
            </if>
            <if condition="$orthosisProcess[2] eq '1'">
                <img class="img-process" id="process3" src="/Template/images/{$processArr.2}.png?v={$imgVersion}" title="修阳模"/>
            </if>
            <if condition="$orthosisProcess[3] eq '1'">
                <img class="img-process" id="process4" src="/Template/images/{$processArr.3}.png?v={$imgVersion}" title="检查修阳模"/>
            </if>
            <if condition="$orthosisProcess[4] eq '1'">
                <img class="img-process" id="process5" src="/Template/images/{$processArr.4}.png?v={$imgVersion}" title="热塑成型"/>
            </if>
            <if condition="$orthosisProcess[5] eq '1'">
                <img class="img-process" id="process6" src="/Template/images/{$processArr.5}.png?v={$imgVersion}" title="检查热塑成型"/>
            </if>
            <if condition="$orthosisProcess[6] eq '1'">
                <img class="img-process" id="process7" src="/Template/images/{$processArr.6}.png?v={$imgVersion}" title="打磨抛光"/>
            </if>
            <if condition="$orthosisProcess[7] eq '1'">
                <img class="img-process" id="process8" src="/Template/images/{$processArr.7}.png?v={$imgVersion}" title="检查打磨抛光"/>
            </if>
            <if condition="$orthosisProcess[8] eq '1'">
                <img class="img-process" id="process9" src="/Template/images/{$processArr.8}.png?v={$imgVersion}" title="组装对线"/>
            </if>
            <if condition="$orthosisProcess[9] eq '1'">
                <img class="img-process" id="process10" src="/Template/images/{$processArr.9}.png?v={$imgVersion}" title="半成品适配"/>
            </if>
            <if condition="$orthosisProcess[10] eq '1'">
                <img class="img-process" id="process11" src="/Template/images/{$processArr.10}.png?v={$imgVersion}" title="穿戴及使用训练"/>
            </if>
            <if condition="$orthosisProcess[11] eq '1'">
                <img class="img-process" id="process12" src="/Template/images/{$processArr.11}.png?v={$imgVersion}" title="入库"/>
            </if>
        </td>
    </div>
</form>
<div class="wrap jj">
    <div class="common-form">
        <form method="post" class="form-horizontal J_ajaxForm" action="{:U('Workorder/outstorePost')}">
            <fieldset>
                <hr class="half-rule">
                <div class="control-group">
                    客户：
                    <select name="client_info_id" readonly>
                        {:getCommonSelectOptionHtml($workorder['client_info_id'], "ClientInfo", "client_info_id", "client_info_name", null, $user['enterprise_code'], 1)}
                    </select>
                    &nbsp;&nbsp;&nbsp;
                    适配方式：
                    <input type="text" class="input" style="width: 80px" name="adapt" value="{$workorder.adapt}" readonly>

                    &nbsp;&nbsp;&nbsp;
                    收货人：
                    <input type="text" class="input" style="width: 80px" name="contact" value="{$workorder.receive_name}" readonly>
                    &nbsp;&nbsp;&nbsp;
                    联系电话：
                    <input type="text" class="input" style="width: 127px" name="mobile" value="{$workorder.receive_contact}" readonly>
                    &nbsp;&nbsp;&nbsp;
                    <br/><br/>
                    地址：
                    <input type="text" class="input" style="width: 810px" name="address" value="{$workorder.receive_address}" readonly>
                    &nbsp;&nbsp;&nbsp;
                    <br/><br/>
                    仓库：
                    <select name="outstore_store_id" readonly style="width: auto">
                        {:getCommonSelectOptionHtml($outstore['store_id'], "Store", "store_id", "store_name", null, $user['enterprise_code'], 1)}
                    </select>
                    &nbsp;&nbsp;&nbsp;
                    付款情况：
                    <select style="width: 120px" name="payment_status" readonly>
                        <option value="{$workorder.payment_status}">请选择</option>
                        {:getFormDictSelectOption($workorder['payment_status'],'paymentStatus','all',0)}
                    </select>
                    <if condition="$workorder['payment_status'] eq '已付定金'">
                        &nbsp;
                        <input type="text" class="input" style="width: 100px" name="deposit" value="{$workorder.deposit}" readonly>&nbsp;元
                    </if>
                    <!--&nbsp;&nbsp;&nbsp;
                    最低百分比：
                    <php>
                        $percent = $outstore["minimum_percent"] * 100;
                    </php>
                    <input type="text" class="input" style="width: 30px;text-align: center;" name="minimum_percent" value="{$percent}" readonly>%
                    <br/><br/>
                    物流公司：
                    <input type="text" class="input" style="width: 130px" name="express_company" value="{$outstore.express_company}">
                    &nbsp;&nbsp;&nbsp;
                    物流单号：
                    <input type="text" class="input" style="width: 150px" name="delivery_number" value="{$outstore.delivery_number}">
                    &nbsp;&nbsp;&nbsp;
                    交货地点：
                    <input type="text" class="input" style="width: 220px" name="delivery_place" value="{$outstore.delivery_place}">
                    &nbsp;&nbsp;&nbsp;-->
                    <br/><br/>
                    备注：
                    <input type="text" class="input" style="width: 750px" name="remark" value="{$outstore.remark}">
                </div>

                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <!--th style="min-width: 150px; width: 150px">编码</th-->
                        <th style="min-width: 200px; ">名称</th>
                        <th style="min-width: 150px; width: 150px">规格型号</th>
                        <th style="min-width: 50px; width: 50px">数量</th>
                        <th style="min-width: 50px; width: 50px">单位</th>
                        <th style="min-width: 60px; width: 60px">销售单价</th>
                        <!--th style="min-width: 50px; width: 50px">折扣率</th-->
                        <th style="min-width: 80px; width: 80px">生产日期</th>
                        <th style="min-width: 80px; width: 80px">有效期至</th>
                        <th style="min-width: 90px; width: 120px">销售金额</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <!--td>
                                <select name="code_id" readonly>
                                    {:getCommonSelectOptionHtml($outstore['code_id'], "CustomizedProduct", "customized_product_id", "customized_product_code",null, $user['enterprise_code'], 1)}
                                </select>
                            </td-->
                            <td><input type="text" class="input" style="text-align: center;width: 95%; height: 10px" name="outstore_name" value="{$outstore.outstore_name}" readonly></td>
                            <td>{$outstore.spec}</td>
                            <td>{$outstore.number}</td>
                            <td>{$outstore.unit}</td>
                            <td>{$workorder.price}&nbsp;元</td>
                            <!--php>
                                $discont = (int)($outstore["sale_price"] * 100 / $workorder["price"])."%";
                            </php>
                            <td><a name="discont">{$discont}</a></td-->
                            <td>{$outstore.production_date}</td>
                            <td>{$outstore.expiry_date}</td>
                            <td><input type="text" class="input" style="text-align: center;width: 80px; height: 10px" name="sale_price" value="{$workorder.price}" onkeyup="onlyNumber(this)" readonly>&nbsp;元</td>
                        </tr>
                    </tbody>
                </table>
                <hr class="half-rule">
                <div class="control-group">
                        出库日期：
                        <input type="text" class="input J_date" style="width: 150px" name="outstore_date" value="{$outstore.outstore_date}">
                        &nbsp;&nbsp;&nbsp;
                        复核人：
                        <select name="outstore_auditor">
                            {:getCommonSelectOptionHtml($outstoreAuditor['employee_id'], "Admin", "employee_id", "admin_name", null, $user['enterprise_code'], 1)}
                        </select>
                </div>
                <hr class="half-rule">
                <php>
                    $btnText = "更新";
                    $btnStatus = -1;
                    $role = explode(',',$user["role"]);
                    if(in_role($role,"4")){
                    if($workorder["outstore_status"] == 1){
                    $btnText = "出库反审核";
                    $btnStatus = 1;
                    }else{
                    $btnText = "更新";
                    $btnStatus = 1;
                    }
                    }
                </php>
                <if condition="$workorder['outstore_status'] neq 1 && $btnStatus eq 1">
                    <div class="control-group">
                        <div class="controls">
                            <label class="checkbox inline" style="font-weight: bold">
                                <input type="checkbox"  name="completed">完成（勾选后提提交则为出库审核）
                            </label>
                        </div>
                    </div>
                </if>
            </fieldset>
            <div class="form-actions">
                <if condition="$btnStatus eq 1">
                    <button type="submit" class="btn btn-primary btn_submit ">{$btnText}</button>
                    <else/>
                    <button disabled="disable" style="background-color: #93949c" class="btn btn-primary btn_submit">{$btnText}</button>
                </if>
                <input type="hidden" name="id" value="{$workorder.workorder_id}" />
                <input type="hidden" name="btnText" value="{$btnText}"/>
                <!--a class="btn" href="__URL__">返回</a-->
                <a class="btn" onclick="window.history.go(-1); ">返回</a>
            </div>
        </form>
    </div>
</div>
<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>